<?php

class Tag_Usertable{
	static $XSL;
}

Tag_Usertable::$XSL = <<<EOD
<xsl:template name="Dec2Hex">
	<xsl:param name="number">0</xsl:param>
	<xsl:variable name="low">
		<xsl:value-of select="\$number mod 16"/>
	</xsl:variable>
	<xsl:variable name="high">
		<xsl:value-of select="floor(\$number div 16)"/>
	</xsl:variable>
	<xsl:choose>
		<xsl:when test="\$high > 0">
			<xsl:call-template name="Dec2Hex">
				<xsl:with-param name="number">
					<xsl:value-of select="\$high"/>
				</xsl:with-param>
			</xsl:call-template>  
		</xsl:when>
		<xsl:otherwise>
			<xsl:text></xsl:text>
		</xsl:otherwise>
	</xsl:choose>  
	<xsl:choose>
		<xsl:when test="\$low &lt; 10">
			<xsl:value-of select="\$low"/>
		</xsl:when>
		<xsl:otherwise>
			<xsl:variable name="temp">
				<xsl:value-of select="\$low - 10"/>
			</xsl:variable>
			<xsl:value-of select="translate(\$temp, '012345', 'abcdef')"/>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>
 
<xsl:template name="toAvatarPath">
 	 <xsl:param name="uid" select="0"/>
	 <xsl:variable name="hex">
	 	<xsl:call-template name="Dec2Hex">
	 		<xsl:with-param name="number" select="\$uid + 4294967296"/>
	 	</xsl:call-template>
	 </xsl:variable>
	 <xsl:value-of select="substring(\$hex, 2,2)"/>/<xsl:value-of select="substring(\$hex, 4,2)"/>/<xsl:value-of select="substring(\$hex, 6,2)"/>/</xsl:template>

<xsl:template name="search-and-replace">
     <xsl:param name="input"/>
     <xsl:param name="search-string"/>
     <xsl:param name="replace-string"/>
     <xsl:choose>
          <!-- See if the input contains the search string -->
          <xsl:when test="\$search-string and 
                           contains(\$input,\$search-string)">
               <xsl:value-of 
                    select="substring-before(\$input,\$search-string)"/>
               <xsl:value-of select="\$replace-string"/>
               <xsl:call-template name="search-and-replace">
                    <xsl:with-param name="input"
                    select="substring-after(\$input,\$search-string)"/>
                    <xsl:with-param name="search-string" 
                    select="\$search-string"/>
                    <xsl:with-param name="replace-string" 
                        select="\$replace-string"/>
               </xsl:call-template>
          </xsl:when>
          <xsl:otherwise>
               <!-- There are no more occurences of the search string so 
               just return the current input string -->
               <xsl:value-of select="\$input"/>
          </xsl:otherwise>
     </xsl:choose>
</xsl:template>

<xsl:template match="i:user-table">
<div class="user-list">
<xsl:if test="@label">
	<h2><xsl:value-of select="@label"/></h2>
</xsl:if>
	<ul>
<xsl:for-each select="./i:user-item">
<xsl:variable name="url">
			<xsl:choose>
				<xsl:when test="/i:user-table/@baseurl">
					<xsl:call-template name="search-and-replace">
						<xsl:with-param name="input" select="/i:user-table/@baseurl"/>
						<xsl:with-param name="search-string" select="'[#uid]'"/>
						<xsl:with-param name="replace-string" select="@uid"/>
					</xsl:call-template>
				</xsl:when>
				<xsl:otherwise>
						/?uid=<xsl:value-of select="@uid"/>
				</xsl:otherwise>
			</xsl:choose>
</xsl:variable>
<xsl:variable name="title">
	<xsl:choose>
		<xsl:when test="@title">
			<xsl:value-of select="@title"/>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="@username"/>
		</xsl:otherwise>
	</xsl:choose>
</xsl:variable>
		<li>
			<div class="avatar50">
			<a>
			<xsl:attribute name="href"><xsl:value-of select="\$url"/></xsl:attribute>
				<img class="avatar">
					<xsl:attribute name="title"><xsl:value-of select="\$title"/></xsl:attribute>
					<xsl:attribute name="src">http://pic1.178.com/avatars/<xsl:call-template name="toAvatarPath"><xsl:with-param name="uid" select="@uid"/></xsl:call-template>50_<xsl:value-of select="@uid"/>.jpg</xsl:attribute>
				</img>
			</a>
			</div>
			<div class="uname "><xsl:if test="@online='true'"><span class="fixie6png online-icon"></span> </xsl:if>
			<a>
			<xsl:attribute name="title"><xsl:value-of select="\$title"/></xsl:attribute>
			<xsl:attribute name="href"><xsl:value-of select="\$url"/></xsl:attribute>
			<xsl:value-of select="@username"/></a></div>
			<xsl:if test="@description"><div class="utime"><xsl:value-of select="@description"/></div></xsl:if>
		</li>
</xsl:for-each>
	</ul>
</div>
</xsl:template>
EOD;
